<?php
/***********************************************
	This class would calculate the details
	required for converting an image to a
	thumbnail.
************************************************/
class ConversionCalculator {
	private $originalImageAspect = NULL;
	private $thumbnailAspect = NULL;
	
	private $newWidth = NULL;
	private $newHeight = NULL;
	private $newWidth_N_HeightArray = NULL;
	
	private $imageWidth = NULL;
	private $imageHeight = NULL;
	
	private $thumbnailWidth = NULL;
	private $thumbnailHeight = NULL;
	
	/************************************************************/
	
	function __construct($imageAttributesArray, $thumbnailAttributesArray) {
		$this->setImage_N_ThumbnailAttributes($imageAttributesArray, $thumbnailAttributesArray);
		$this->setImage_N_ThumbnailAspects();
	}
	
	/************************************************************/
	
	function setImage_N_ThumbnailAttributes($imageAttributesArray, $thumbnailAttributesArray) {
		$this->imageWidth = $imageAttributesArray['imageWidth'];
		$this->imageHeight = $imageAttributesArray['imageHeight'];
		
		$this->thumbnailWidth = $thumbnailAttributesArray['thumbnailWidth'];
		$this->thumbnailHeight = $thumbnailAttributesArray['thumbnailHeight'];
	}
	
	/************************************************************/
	
	function setImage_N_ThumbnailAspects() {
		$this->originalImageAspect = $this->imageWidth / $this->imageHeight;
		$this->thumbnailAspect = $this->thumbnailWidth / $this->thumbnailHeight;
	}
	
	/************************************************************/
	
	function setNewWidth_N_Height() {
		if ($this->originalImageAspect >= $this->thumbnailAspect) {
			$this->newHeight = $this->thumbnailHeight;
			$this->newWidth = $this->imageWidth / ($this->imageHeight / $this->thumbnailHeight);
		} else {
			$this->newWidth = $this->thumbnailWidth;
			$this->newHeight = $this->imageHeight / ($this->imageWidth / $this->thumbnailWidth);
		}
		
		$this->newWidth_N_HeightArray = array();
		$this->newWidth_N_HeightArray['newWidth'] = $this->newWidth;
		$this->newWidth_N_HeightArray['newHeight'] = $this->newHeight;
		
		return $this->newWidth_N_HeightArray;
	}
}
?>